package com.bai.api.controller;

import com.bai.api.common.Ret;
import com.bai.api.entity.Article;
import com.bai.api.service.ArticleService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

@RestController
@CrossOrigin
public class ArticleController {

    @Resource
    private ArticleService articleService;

    @PostMapping("/article/findById")
    @ResponseBody
    public Ret findById(Article article){
        Article entity = articleService.findById(article);

        if(null != entity){
            return new Ret(true,"",entity);
        }else{
            return new Ret(false,"",null);
        }

    }

    @PostMapping("/article/findList")
    @ResponseBody
    public Ret findList(Article article){
        List<Article> entity = articleService.findList(article);

        if(null != entity){
            return new Ret(true,"",entity);
        }else{
            return new Ret(false,"",null);
        }

    }
    @PostMapping("/article/findByTitle")
    @ResponseBody
    public Ret findByTitle(Article article){
        List<Article> entity = articleService.findByTitle(article);

        if(null != entity){
            return new Ret(true,"",entity);
        }else{
            return new Ret(false,"",null);
        }

    }

    @PostMapping("/article/save")
    @ResponseBody
    public Ret save(Article article){
        Article entity = articleService.save(article);

        if(null != entity){
            return new Ret(true,"",entity);
        }else{
            return new Ret(false,"",null);
        }

    }

    @PostMapping("/article/delete")
    public void delete(Article article){
        articleService.delete(article);
    }


}
